package cn.itcast.eduservice.controller;


import cn.itcast.commonutils.R;
import cn.itcast.eduservice.entity.vo.CourseInfoVo;
import cn.itcast.eduservice.entity.vo.CoursePublishVo;
import cn.itcast.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Duanzihuang
 * @since 2020-05-19
 */
@Api(description = "课程管理")
@RestController
@CrossOrigin
@RequestMapping("/eduservice/course")
public class EduCourseController {
    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("/addCourseInfo")
    @ApiOperation(value = "添加课程信息")
    public R addCourseInfo(@RequestBody CourseInfoVo courseInfoVo) {
        String cid = eduCourseService.saveCourseInfo(courseInfoVo);
        return R.ok().data("courseId",cid);
    }

    @ApiOperation(value = "根据课程Id获取课程信息")
    @GetMapping("/getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId) {
        CourseInfoVo courseInfoVo = eduCourseService.getCourseInfoById(courseId);
        return R.ok().data("courseInfo",courseInfoVo);
    }

    @ApiOperation(value = "更新课程")
    @PostMapping("/updateCourseInfo")
    public R updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo) {
        eduCourseService.updateCourseInfo(courseInfoVo);
        return R.ok();
    }

    // 删除课程
    @ApiOperation(value = "删除课程")
    @DeleteMapping("{courseId}")
    public R deleteCourse(@PathVariable String courseId) {
        eduCourseService.removeCourse(courseId);
        return R.ok();
    }

    // 根据课程id查询课程确认信息
    @ApiOperation(value = "根据id查询课程确认信息")
    @GetMapping("getPublishCourseInfo/{id}")
    public R getPublishCourseInfo(@PathVariable String id){
        CoursePublishVo coursePublishVo = eduCourseService.getPublishCourseInfo(id);

        return R.ok().data("publishCourse",coursePublishVo);
    }
}

